<template>
  <div id="app" >
      <el-input v-model="aftersaleSn" placeholder="请输入售后编号" style="width:300px"></el-input>
      <el-input v-model="orderId" placeholder="请输入订单编号" style="width:300px"></el-input>
    <el-button @click="getKeyList" type="primary" size="small">查询</el-button>&nbsp;&nbsp;
    <el-button @click="toggleSelection()" type="primary"  size="small">取消选择</el-button>&nbsp;&nbsp;&nbsp;&nbsp;
    <el-button @click="pltg()" type="success" round size="small">批量通过</el-button>
    <el-button @click="pljj()" type="danger" round size="small">批量拒绝</el-button><br>
     <el-button @click="quan()"  type="text" size="small"  >全部</el-button>&nbsp;
     <el-button @click="shenhe()"  type="text" size="small"   >待审核</el-button>&nbsp;
     <el-button @click="tuikuan()"  type="text" size="small"  >待退款</el-button>
    <el-table  ref="multipleTable" :data="tableData" border style="width: 85%"  tooltip-effect="dark"    @selection-change="handleSelectionChange">
        <el-table-column type="selection" prop="id" label="ID"  width="120"></el-table-column>
      <el-table-column prop="aftersaleSn" label="售后编号"  width="100"></el-table-column>
      <el-table-column prop="orderId" label="订单ID"  width="100"></el-table-column>
      <el-table-column prop="userId" label="用户ID"  width="100"></el-table-column>
       <el-table-column prop="type" label="售后类型"  :formatter="formatter"  width="200" ></el-table-column>
       <el-table-column prop="reason" label="退款原因"  width="120" ></el-table-column>
       <el-table-column prop="amount" label="退款价格"  width="100" ></el-table-column>
       <el-table-column prop="handleTime" label="申请时间"  width="120" ></el-table-column>
         <el-table-column fixed="right" label="操作" width="90">
        <template slot-scope="scope">
          <el-button @click="delClick(scope.row.id)" type="danger" size="small">删除</el-button> 
        </template>
      </el-table-column>
    </el-table>
     <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="currentPage4"
      :page-sizes="[1, 3, 6, 10]"
      :page-size="pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>
  </div>
</template>

<script>
export default {
  mounted() {
    this.getKeyList();
  },
  methods: {
        toggleSelection(rows) {
        if (rows) {
          rows.forEach(row => {
            this.$refs.multipleTable.toggleRowSelection(row);
          });
        } else {
          this.$refs.multipleTable.clearSelection();
        }
      },
       handleSelectionChange(row) {
        this.multipleSelection = row;
      },
      quan(){
         var $this=this;
         $this.status='';
         $this.getKeyList();
      },
      tuikuan(){
         var $this=this;
         $this.status=2;
         $this.getKeyList();
      },
      shenhe(){
        var $this=this;
          $this.status=1;
         $this.getKeyList();
      },
       pltg(){
          var $this=this;
          var ids=[];
          for(var i=0;i<$this.multipleSelection.length;i++){
              var tmp = $this.multipleSelection[i];
              ids.push(tmp.id);
          }
        this.axios({
        method: "POST",
        url: "http://localhost:9999/market/ecAftersale/xujiabao/plUpd?ids="+ids,
      }).then(function(res) {
          if(res.data.code==200){
              $this.getKeyList();
          }
      });
      },
      pljj(row){
          var $this=this;
          var ids=[];
          for(var i=0;i<$this.multipleSelection.length;i++){
              var tmp = $this.multipleSelection[i];
              ids.push(tmp.id);
          }
        this.axios({
        method: "POST",
        url: "http://localhost:9999/market/ecAftersale/xujiabao/plNo?ids="+ids,
      }).then(function(res) {
          if(res.data.code==200){
              $this.getKeyList();
          }
      });
      },
     formatter(row) {
      if (row.type != null) {
        if (row.type == 0) {
          return "未收货退款";
        } else if (row.type == 1) {
          return "已收货（无需退货）退款";
        } if (row.type == 2) {
          return "用户退货退款";
        }
      }
    },
    getKeyList() {
      var $this=this;
      this.axios({
        method: "GET",
        url: "http://localhost:9999/market/ecAftersale/xujiabao/afterlist",
        params: {
          pageNo: this.currentPage4,
          pageSize: this.pageSize,
           orderId:this.orderId,
           aftersaleSn:this.aftersaleSn,
           status:this.status
        }
      }).then(function(res) {
        $this.tableData = res.data.obj.list;
        $this.total=res.data.obj.total;
      });
    },
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pageSize = val;
      this.getKeyList();
    },
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.currentPage4 = val;
      this.getKeyList();
    },
    delClick(row){
      var $this=this;
      this.axios({
        method:'post',
        url: "http://localhost:9999/market/ecAftersale/xujiabao/logicdel?id="+row,
      }).then(function(res){
          if(res.data.code==200){
              alert("删除成功");
              $this.getKeyList();
          }else{
            alert("删除有误");
          }
      })
    },
  },
  data() {
    return {
      msg: "Welcome to Your Vue.js App",
      currentPage4: 1,
      pageSize: 10,
      tableData: [],
      total: 0,
      dialogFormVisible: false,
      updFlag:false,
      form: {
      },
      rules: {},
      formLabelWidth: "120px",
      aftersaleSn:'',
      orderId:'',
      multipleSelection: [],
      status:'',
    };
  }
};
</script>

